package document;

import treemodel.Node;
import treeview.NodeView;

/**
 * Created by Pavel Nikolaev
 */

public class HtmlDocument {
    private Node myRoot;
    private String myTitle;
    private String myNakedText;
    private char myTagSubstitutionSymbol;

    public HtmlDocument(String title, Node root, String text, char tagSubstitute) {
        myRoot = root;
        myRoot.prepareForWrapping();
        myTitle = title;
        myNakedText = text;
        myTagSubstitutionSymbol = tagSubstitute;
    }

    public NodeView createView(Context context) {
        return myRoot.createView(context);
    }

    public String getRefinedText(int startOffset, int endOffset) throws IndexOutOfBoundsException {
        char[] source = myNakedText.substring(startOffset, endOffset).toCharArray();
        String result = "";
        for (char ch : source) {
            result += (ch == myTagSubstitutionSymbol) ? ' ' : ch;
        }
        return result;
    }
}
